package com.arpa.wms.service.impl;

import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.wms.domain.dto.PickingDTO;
import com.arpa.wms.domain.dto.WmsTaskDTO;
import com.arpa.wms.domain.vo.PickingTaskDetailVO;
import com.arpa.wms.domain.vo.WmsTaskVO;
import com.arpa.wms.service.IPickingService;
import com.arpa.wms.service.IWmsPickingTaskService;
import com.arpa.wms.service.IWmsTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * @author: Allen chen
 * @Date 2020/10/16
 * @Description:
 */
@Service
public class WmsPickingTaskServiceImpl implements IWmsPickingTaskService {

    @Autowired
    private IWmsTaskService taskService;

    @Autowired
    @Lazy
    private IPickingService iPickingService;

    @Override
    public PickingTaskDetailVO taskDetail(String code) {
        String branchCode = UserUtil.getBranchCode();
        WmsTaskDTO taskDTO = new WmsTaskDTO();
        taskDTO.setCode(code);
        WmsTaskVO wmsTaskVO = taskService.queryPickingTaskByCode(taskDTO);
        if(null == wmsTaskVO){
            throw new ServiceException("拣货任务信息查询错误！");
        }
        PickingDTO dto = new PickingDTO();
        dto.setCode(wmsTaskVO.getSourceCode());
        dto.setGroupCode(branchCode);
        PickingTaskDetailVO taskDetailByCode = iPickingService.getTaskDetailByCode(dto);
        if(null == taskDetailByCode){
            throw new ServiceException("拣货任务明细信息查询错误！");
        }
        return taskDetailByCode;
    }

    @Override
    public PickingTaskDetailVO detail(String taskCode,String locationCode) {

        return null;
    }
}
